//
//  ZLCommentTableViewCell.m
//  TripTogether
//
//  Created by dllo on 15/12/31.
//  Copyright © 2015年 王军岐. All rights reserved.
//

#import "ZLCommentTableViewCell.h"

#import "StarView.h"

@interface ZLCommentTableViewCell ()

@property (nonatomic, strong)UIImageView *headImageV;//头像
@property (nonatomic, strong)UILabel *nameLabel;
@property (nonatomic, strong)UILabel *dateLabel;
@property (nonatomic, strong)UILabel *textsLabel;
@property (nonatomic, strong)StarView *starV;
@property (nonatomic, strong)UIView *lineView;
@end

@implementation ZLCommentTableViewCell
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self createSubView];
    }
    return self;
}

- (void)createSubView
{
    self.headImageV = [UIImageView new];
    [self.contentView addSubview:self.headImageV];
//    self.headImageV.backgroundColor = [UIColor redColor];
    [self.headImageV mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.contentView.mas_left).offset(10);
        make.top.equalTo(self.contentView.mas_top).offset(20);
        make.width.height.equalTo(@(40*AUTO_HEIGHT));
    }];
    self.headImageV.layer.masksToBounds = YES;
    self.headImageV.layer.cornerRadius = 20*AUTO_WIDTH;
    
    self.nameLabel = [UILabel new];
    [self.contentView addSubview:self.nameLabel];
//    self.nameLabel.backgroundColor = [UIColor yellowColor];
    self.nameLabel.font = [UIFont systemFontOfSize:16.0f];
    [self.nameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.headImageV.mas_right).offset(10);
        make.top.equalTo(self.contentView.mas_top).offset(20);
        make.width.equalTo(@200);
        make.height.equalTo(@(20*AUTO_HEIGHT));
    }];
    
    self.starV = [[StarView alloc]initWithFrame:CGRectMake(60*AUTO_WIDTH, 40*AUTO_HEIGHT, 50*AUTO_WIDTH, 20*AUTO_HEIGHT) number:5];
    [self.contentView addSubview:self.starV];
    
    self.dateLabel = [UILabel new];
    self.dateLabel.backgroundColor = [UIColor clearColor];
    [self.contentView addSubview:self.dateLabel];
    self.dateLabel.textAlignment = NSTextAlignmentRight;
    [self.dateLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.nameLabel.mas_right);
        make.right.equalTo(self.contentView.mas_right).offset(-10);
        make.top.equalTo(self.contentView.mas_top).offset(20);
        make.height.equalTo(@(19*AUTO_HEIGHT));
    }];
    
    self.textsLabel = [UILabel new];
    [self.contentView addSubview:self.textsLabel];
    self.textsLabel.lineBreakMode = NSLineBreakByWordWrapping;
    self.textsLabel.numberOfLines = 0;
    
    self.lineView = [UIView new];
    [self.contentView addSubview:self.lineView];
    self.lineView.backgroundColor = [UIColor lightGrayColor];
    
}

-(void)setSecondM:(ZLSecondModel *)secondM
{
    [self.textsLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.starV.mas_bottom).offset(5);
        make.left.equalTo(self.contentView.mas_left).offset(10);
        make.right.equalTo(self.contentView.mas_right).offset(-10);
        make.height.mas_equalTo(secondM.height);
    }];
    [self.lineView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.headImageV.mas_left).offset(10);
        make.right.equalTo(self.contentView.mas_right).offset(-10);
        make.bottom.equalTo(self.contentView.mas_bottom);
        make.height.equalTo(@(1*AUTO_HEIGHT));
    }];
    
    [self.headImageV sd_setImageWithURL:[NSURL URLWithString:[[secondM zlUserM] avatar_m]] placeholderImage:PICHOLDEER];

    self.nameLabel.text = [[secondM zlUserM].name stringByAppendingString:[@"Lv" stringByAppendingString:[NSString stringWithFormat:@"%ld",[[[[secondM zlUserM] zlExperienceM] zlValueM] value]]]];
    self.textsLabel.text = secondM.content;
    NSRange range = {0,10};
    self.dateLabel.text = [secondM.datetime stringByReplacingCharactersInRange:range withString:@""];
    
    [self.starV setStarWithNumber:secondM.rating];
    
}




- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];
    
    // Configure the view for the selected state
}

@end
